/*
 * editData.java
 *
 * Created on __DATE__, __TIME__
 */

package hotel.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;

import hotel.dao.BianJiDao;
import hotel.util.DbUtil;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;


public class editData extends javax.swing.JInternalFrame {

	DbUtil dbUtil = new DbUtil();
	BianJiDao editModulDao = new BianJiDao();

	public editData() {
		initComponents();
		this.setLocation(300, 100);//设置窗口位置
	}
	private void initComponents() {

		jLabel1 = new JLabel();

		jLabel1.setFont(new Font("宋体", Font.PLAIN, 22));
		jTextField1 = new JTextField();
		jLabel2 = new JLabel();

		jLabel2.setFont(new Font("宋体", Font.PLAIN, 22));
		password = new JPasswordField();
		password2 = new JPasswordField();
		jButton1 = new JButton();

		jButton1.setFont(new Font("宋体", Font.PLAIN, 22));

		setClosable(true);
		setTitle("修改资料");

		jLabel1.setText("账号");

		jTextField1.setEditable(false);
		jTextField1.setText("admin");

		jLabel2.setText("密码");

		jButton1.setText("修改");
		jButton1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		layout.setHorizontalGroup(
			layout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, layout.createSequentialGroup()
					.addGroup(layout.createParallelGroup(Alignment.TRAILING)
						.addGroup(Alignment.LEADING, layout.createSequentialGroup()
							.addGap(127)
							.addGroup(layout.createParallelGroup(Alignment.LEADING)
								.addGroup(layout.createSequentialGroup()
									.addComponent(jLabel1)
									.addPreferredGap(ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
									.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGroup(layout.createSequentialGroup()
									.addComponent(jLabel2)
									.addPreferredGap(ComponentPlacement.RELATED, 377, Short.MAX_VALUE))))
						.addGroup(Alignment.LEADING, layout.createSequentialGroup()
							.addGap(203)
							.addComponent(jButton1)
							.addPreferredGap(ComponentPlacement.RELATED, 268, Short.MAX_VALUE))
						.addGroup(layout.createSequentialGroup()
							.addGap(283)
							.addComponent(password, 0, 0, Short.MAX_VALUE)))
					.addGap(129))
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(Alignment.LEADING)lGroup()
					.addContainerGap(123, Short.MAX_VALUE)
				.addGroup(Alignment.TRAILING, layout.createSequentia
					.addGroup(layout.createParallelGroup(Alignment.BASELINE)
						.addComponent(jLabel1)
						.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
					.addGap(42)
					.addGroup(layout.createParallelGroup(Alignment.BASELINE)
						.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addComponent(jLabel2))
					.addGap(53)
					.addComponent(jButton1)
					.addGap(99))
		);
		getContentPane().setLayout(layout);

		pack();
	}

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		String password = new String(this.password.getPassword());
		String repassword = new String(this.password2.getPassword());
		if (password == null || "".equals(password)) {
			JOptionPane.showMessageDialog(null, "请输入密码");
			return;
		}
		if(!password.equals(repassword)){
			JOptionPane.showMessageDialog(null, "两次输入密码不一致");
			return;
		}
		Connection con = null;
		//修改数据库操作
		try {
			con = dbUtil.getCon();
			int result = editModulDao.updateAdmin(con, password);
			if (result != 0) {
				JOptionPane.showMessageDialog(null, "修改成功");
				this.password.setText("");
			} else {
				JOptionPane.showMessageDialog(null, "修改失败");
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				dbUtil.closeCon(con);//关闭数据库连接
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	private JButton jButton1;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JTextField jTextField1;
	private JPasswordField password;
	private JPasswordField password2;
	

}